/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package questionaire.resources;

import inferenceEngine.labels.Label;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author aqeel
 */
public class ProcessAnswer
{
    public ProcessAnswer()
    {
        
    }
    
    public ArrayList<Label> returnLabels(Map optionClicked,Map inferenceMap)
    {
        Set optionSet = optionClicked.keySet();
        ArrayList<Label> labelList = new ArrayList<Label>();
        for(Integer questionNo = 1;questionNo<=optionClicked.size();++questionNo)
        {
            List optionValues = (List)optionClicked.get(questionNo);
            Map map = new LinkedHashMap();
            map = (Map)inferenceMap.get(questionNo);
            if(map!=null)
            {
                for(Object optionValue : optionValues)
                    labelList.add(new Label(String.valueOf(map.get((Integer)optionValue))));
            }
        }
        return labelList;
    }
    
    public void displayRules(Map optionClicked,Map inferenceMap,JPanel rulesPanel)
    {
        try
        {
            Set optionSet = optionClicked.keySet();
            ArrayList<Label> labelList = new ArrayList<Label>();
            rulesPanel.setLayout(new GridLayout(optionClicked.size(), 1));
            for(Integer questionNo = 1;questionNo<=optionClicked.size();++questionNo)
            {
                Integer optionValue = (Integer)optionClicked.get(questionNo);
                Map map = new LinkedHashMap();
                map = (Map)inferenceMap.get(questionNo);
                JLabel ruleLabel = new JLabel();
                if(map!=null)
                {
                    ruleLabel.setText("Question "+questionNo+" : "+map.get(optionValue));
                    ruleLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                }
                else
                {
                    ruleLabel.setText("Question "+questionNo+" : No rules found");
                    ruleLabel.setFont(new Font(Font.SANS_SERIF,Font.PLAIN,16));
                }
                rulesPanel.add(ruleLabel);
            }
            rulesPanel.setVisible(false);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
